namespace Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Categories",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        CreatedOn = c.DateTime(nullable: false),
                        ModifiedOn = c.DateTime(),
                        Name = c.String(),
                        Description = c.String(),
                        CreatedBy_Id = c.Guid(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.CreatedBy_Id)
                .Index(t => t.CreatedBy_Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        CreatedOn = c.DateTime(nullable: false),
                        ModifiedOn = c.DateTime(),
                        Username = c.String(),
                        Password = c.String(),
                        ValidationKey = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Websites",
                c => new
                    {
                        Id = c.Guid(nullable: false),
                        CreatedOn = c.DateTime(nullable: false),
                        ModifiedOn = c.DateTime(),
                        Name = c.String(),
                        Url = c.String(),
                        Description = c.String(),
                        Ranking = c.Int(nullable: false),
                        CreatedBy_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Users", t => t.CreatedBy_Id, cascadeDelete: true)
                .Index(t => t.CreatedBy_Id);
            
            CreateTable(
                "dbo.WebsiteCategories",
                c => new
                    {
                        Website_Id = c.Guid(nullable: false),
                        Category_Id = c.Guid(nullable: false),
                    })
                .PrimaryKey(t => new { t.Website_Id, t.Category_Id })
                .ForeignKey("dbo.Websites", t => t.Website_Id, cascadeDelete: true)
                .ForeignKey("dbo.Categories", t => t.Category_Id, cascadeDelete: true)
                .Index(t => t.Website_Id)
                .Index(t => t.Category_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.Websites", "CreatedBy_Id", "dbo.Users");
            DropForeignKey("dbo.WebsiteCategories", "Category_Id", "dbo.Categories");
            DropForeignKey("dbo.WebsiteCategories", "Website_Id", "dbo.Websites");
            DropForeignKey("dbo.Categories", "CreatedBy_Id", "dbo.Users");
            DropIndex("dbo.Websites", new[] { "CreatedBy_Id" });
            DropIndex("dbo.WebsiteCategories", new[] { "Category_Id" });
            DropIndex("dbo.WebsiteCategories", new[] { "Website_Id" });
            DropIndex("dbo.Categories", new[] { "CreatedBy_Id" });
            DropTable("dbo.WebsiteCategories");
            DropTable("dbo.Websites");
            DropTable("dbo.Users");
            DropTable("dbo.Categories");
        }
    }
}
